import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from common.base import Base
from page.login_page import BackLoginPage


class Order_Management(Base):
    def order(self):
        # 进入订单管理
        self.click((By.XPATH, '//html/body/div/div[3]/div[1]/ul/li[4]'))
        self.driver.switch_to.default_content()  # 切换主页面
        # 定位进入嵌套
        frame1 = self.find_element((By.XPATH, '//frameset[@framespacing="0" and @rows="100,*"]/frame[2]'))
        self.driver.switch_to.frame(frame1)

    def a_search(self):
        # 进入高级搜索
        self.click((By.XPATH, "/html/body/div[1]/form/span"))

    def input_order_number(self, order_number):
        # 定位输入订单号
        self.send_keys((By.XPATH, '/html/body/div[2]/form/div/div[2]/table/tbody/tr[1]/td[2]/input'), order_number)

    def input_consignee(self, consignee):
        # 定位输入收货人
        self.send_keys((By.XPATH, '/html/body/div[2]/form/div/div[2]/table/tbody/tr[3]/td[4]/input'), consignee)

    def input_location(self):
        # 创建select对象，参数为要操作的select标签
        s1 =self.driver.find_element(By.ID, 'selCountries')
        select1 =Select(s1)
        s2 =self.driver.find_element(By.ID, 'selProvinces')
        select2 =Select(s2)
        s3 =self.driver.find_element(By.ID, 'selCities')
        select3 =Select(s3)
        # 选择option
        time.sleep(2)
        select1.select_by_index(1)
        time.sleep(2)
        select2.select_by_value("18")
        time.sleep(2)
        select3.select_by_visible_text("武汉市")

    def search(self):
        self.click((By.ID, 'query'))

    def order_no(self):
        return self.get_element_text((By.ID, 'order_0'))

